﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioCtrl : MonoBehaviour
{
    public AudioClip Clip1;
    public AudioClip Clip2;
    public AudioClip Clip3;
    public AudioClip Clip4;
    public AudioSource aSource1;
    public AudioSource aSource2;
    public AudioSource aSource3;
    public AudioSource aSource4;
    public AudioSource aFxSource1;
    public AudioSource aFxSource2;
    public AudioSource aFxSource3;
    public int num;
    public Dictionary<int, AudioClip> dictClip;
    public Dictionary<int, AudioSource> dictSource;
    public Dictionary<int, AudioSource> dictAFx;
    // Use this for initialization
    void Start()
    {
        dictClip = new Dictionary<int, AudioClip>();
        dictSource = new Dictionary<int, AudioSource>();
        dictAFx = new Dictionary<int, AudioSource>();
        dictClip.Add(0, Clip1);
        dictClip.Add(1, Clip2);
        dictClip.Add(2, Clip3);
        dictClip.Add(3, Clip4);
        dictSource.Add(0, aSource1);
        dictSource.Add(1, aSource2);
        dictSource.Add(2, aSource3);
        dictSource.Add(3, aSource4);
        dictSource.Add(4, aFxSource1);
        dictSource.Add(5, aFxSource2);
        dictAFx.Add(0, aFxSource1);
        dictAFx.Add(1, aFxSource2);
        dictAFx.Add(2, aFxSource3);
        //aSource1.Play();
        var btn1 = this.transform.Find("Button1").GetComponent<UnityEngine.UI.Button>();
        btn1.onClick.AddListener(onBtn1Down);
    }
    void onBtn1Down()
    {
        AddAudio(num);
        //        AudioFxOnce(0);
        num++;
        if (num >= dictClip.Count)
        {
            num = 0;
        }
    }
    void onBtn2Down()
    {
        AudioFxOnce(0);
    }

    public void AddAudio(int i)
    {
        AudioSource Source = dictSource[i];
        Source.Play();
    }

    public void AudioFxOnce(int i)
    {
        dictAFx[i].PlayOneShot(dictClip[i]);
    }

    // Update is called once per frame
    void Update()
    {

    }
}
